import axios from 'axios'
import { getToken, removeToken } from './token'
const instance = axios.create({
    baseURL: process.env.REACT_APP_BASEURL,
    timeout: 60000
})
// 请求拦截器
instance.interceptors.request.use(
    config => {
        const token = getToken()
        if (token) {
            config.headers.authorization = token
        }
        return config
    },
    err => {
        console.log(err)
    }
)
// 响应拦截器
instance.interceptors.response.use(
    response => {
        if (response.data.status === 400) {
            removeToken()
        }
        return response
    },
    error => {
        return Promise.reject(error)
    }
)
export default instance